import { Component, forwardRef } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR,CUSTOM_ELEMENTS_SCHEMA } from "@angular/forms";
import { JmessageProvider } from '../../providers/jmessage/jmessage';
/**
 * Generated class for the EmojiComponent component.
 *
 * See https://angular.io/api/core/Component for more info on Angular
 * Components.
 */
export const EMOJI_PICKER_VALUE_ACCESSOR: any = {
	provide: NG_VALUE_ACCESSOR,
	useExisting: forwardRef(() => EmojiComponent),
	multi: true
};

@Component({
	selector: 'emoji',
	providers: [EMOJI_PICKER_VALUE_ACCESSOR],
	templateUrl: 'emoji.html'
})
export class EmojiComponent implements ControlValueAccessor {

	private emojiArr: any;

	public _content: string;
	public _onChanged: Function;
	public _onTouched: Function;

	constructor(public jmenssage: JmessageProvider) {
		this.emojiArr = new Array();
		console.log('Hello EmojiComponent Component');
		this.emojiArr = jmenssage.getEmojis();
	}

	writeValue(obj: any): void {
		this._content = obj;
	}

	registerOnChange(fn: any): void {
		this._onChanged = fn;
		this.setValue(this._content);
	}

	registerOnTouched(fn: any): void {
		this._onTouched = fn;
	}

	private setValue(val: any): any {
		this._content += val;
		if(this._content) {
			this._onChanged(this._content)
		}
	}
}